# -*-utf-8-*-

import os
import cv2
import time
import random
import filesystem
import shutil

if __name__ == "__main__":
    cnt = 0  # 计数器

    rootDir = r'F:\work\dataset\pic\changshun\car\weather2'
    dirPath = filesystem.get_all_filepath(rootDir)
    for path in dirPath:

        # 文件保存路径
        saveDir = r'E:\gec\picture\cls'

        # [-5: -1]是2021，12...到文件名前的索引
        temSubName1 = path.split('\\')[-5: -1]
        subName1 = "_".join(temSubName1)
        subPath = temSubName1[0]  # 分路径

        # 原文件名
        subName2 = os.path.basename(path).split('.')[0]

        fileName = '{}_{}.jpg'.format(subName1, subName2)
        file = os.path.join(saveDir, subPath, fileName)

        # 判断文件夹是否存在
        if os.path.exists(os.path.dirname(file)) is not True:
            os.makedirs(os.path.dirname(file))

        shutil.copy(path, file)

        cnt += 1
        print("\n正在复制第{}张".format(cnt))
    print("截取完成，共复制{}张".format(cnt))
